package com.htt.bms.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 侯婷婷
 * @version 1.0
 *
 * Result 泛型类，用于客户端与服务端通讯
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private String code;//状态码
    private String msg;//信息
    private T data;//数据

    //成功，不携带数据的普通静态方法
    public static Result success(){
        Result<Object> result = new Result<>();
        result.setCode("200");
        result.setMsg("success");
        return result;
    }

    //成功，携带数据的泛型静态方法
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode("200");
        result.setData(data);
        return result;
    }

    //失败，不携带data数据
    public static Result error(String code, String msg){
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    //失败，携带数据的泛型静态方法
    public static <T> Result<T> error(String code, String msg, T data){
        Result<T> result = new Result<>(code, msg, data);
        return result;
    }
}
